#include <iostream>
using namespace std;

class people
{
private:
    string name;
    int age;
    char sex;
    bool ishun;
public:
    

    void init();
    void show();
    void jiehun(people & ren);

    people(const people & ren);
    people(string name,int age,char sex,bool ishun);
    ~people();
};

people::people(string name,int age,char sex,bool ishun):name(name),age(age),sex(sex),ishun(ishun)
{
    cout << "有参构造" << endl;
}

people::~people()
{
    cout << "析构函数" << endl;
}

int main()
{
    people li("李华",28,'n',false);
    li.show();
    people zhang("张三" ,28,'v',false);
    zhang.show();
    li.jiehun(zhang);
    zhang.show();
    li.show();
    return 0;
}

void people::init()
{
    name = "无名氏";
    age = 0;
    ishun = false;
    sex = 'n';
}

void people::show()
{
    cout << "名字是：" << name <<",年龄是: " 
    << age <<" 性别是：" << sex << " 是否婚配:"
     << ishun << endl;
}

void people::jiehun(people&ren)
{
    if(ren.sex == sex)
    {
        cout << "不要搞基啊 " << endl;
        return ;
    }
    else if(ren.ishun )
    {
        cout << "对方已经结婚了  "  << endl;
        return ;
    }
    else if(ishun)
    {
        cout << "你已经结婚了  "  << endl;
        return ;
    }

    // 检查法定结婚年龄
    bool canMarry = true;
    if(sex == 'n')
    {
        if(age < 22)
        {
            cout << "你的年龄太小 不能结婚 " << endl;
           canMarry = false;
        }else if(ren.sex == 'v')
        {
            if(ren.age < 20)
            {
                cout << "对方的年龄太小 不能结婚" << endl;
                canMarry = false;
            }
        }
    }
    else if(sex == 'v')
    {
         if(age < 20)
        {
            cout << "你的年龄太小 不能结婚 " << endl;
           canMarry = false;
        }else if(ren.sex == 'n')
        {
            if(ren.age < 22)
            {
                cout << "对方的年龄太小 不能结婚" << endl;
                canMarry = false;
            }
        }
    }
    // 如果所有条件都满足，则结婚
    if (canMarry) {
        ishun = true;
        ren.ishun = true;
        cout << name << " 和 " << ren.name << " 结婚了" << endl;
    }
}


